package com.shuqi.common.utils;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import com.shuqi.common.LoginHelper;

/**
 * yanghuawei
 */
public class HttpCommonParamsUtils {

    /**
     * 所有账户接口需要Post加密验证的统一验证方式
     * 
     * @return
     */
    public static List<BasicNameValuePair> getAccountBasicParams() {
        List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
        String key = "c56cf32e9a52a265ae47cd50570266cc";
        String timestamp = String.valueOf(System.currentTimeMillis());
        String md5_key = Util.MD5(key + timestamp);
        params.add(new BasicNameValuePair("key", md5_key));// md5
        params.add(new BasicNameValuePair("timestamp", timestamp));// 时间戳
        return params;
    }

    /**
     * 书旗接口的Post加密验证
     * 
     * @return
     */
    public static List<BasicNameValuePair> getShuQiBasicParams(String userId) {
        List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
        String timestamp = String.valueOf(System.currentTimeMillis());
        String strTimestamp = timestamp + userId;
        String md5_key = Util.MD5(LoginHelper.Encrypt(strTimestamp));
        params.add(new BasicNameValuePair("PostTime", timestamp));// 时间戳
        params.add(new BasicNameValuePair("PostToken", md5_key));// md5
        return params;
    }
    /**
     * 书旗接口的Post加密验证
     * 
     * @return
     */
    public static JSONObject getShuQiBasicParamsOfJson(String userId) {
        JSONObject jsonObject = new JSONObject();
        String timestamp = String.valueOf(System.currentTimeMillis());
        String strTimestamp = timestamp + userId;
        String md5_key = Util.MD5(LoginHelper.Encrypt(strTimestamp));
        try {
            jsonObject.put("PostTime", timestamp);
            jsonObject.put("PostToken", md5_key);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return jsonObject;
    }
}
